#include <websocketpp/config/asio_no_tls.hpp>  
#include <websocketpp/server.hpp>
#include <iostream>
typedef websocketpp::server<websocketpp::config::asio> server_t;
void onOpen(websocketpp::connection_hdl hdl)
{
    std::cout << "websocket长链接建立成功" << std::endl;
}
void onClose(websocketpp::connection_hdl hdl)
{
    std::cout << "长链接断开" << std::endl;
}
void onMessage(server_t * server,websocketpp::connection_hdl hdl, server_t::message_ptr msg)
{
    std::cout << "收到消息" << msg->get_payload()<< std::endl;

    auto conn = server->get_con_from_hdl(hdl);
    conn->send(msg->get_payload() + "hello!!!!!!",websocketpp::frame::opcode::value::text);
}
int main()
{
    server_t server;
    server.set_access_channels(websocketpp::log::alevel::none);//关闭日志

    server.init_asio();//初始化asio
    server.set_open_handler(onOpen);//设置连接打开回调
    server.set_close_handler(onClose);//设置连接关闭回调
    auto msg_handler =std::bind(onMessage,&server,std::placeholders::_1,std::placeholders::_2);
    server.set_message_handler(msg_handler);//设置消息处理回调
    server.set_reuse_addr(true);//启用地址重用
    server.listen(9090);//监听端口
    server.start_accept();//开始接受连接/开始监听
    server.run();//让服务器跑起来
    return 0;


}